<template>
	<view class="message-page">
		<!-- 标题栏 -->
		<view class="page-header">
			<text class="header-title">问诊消息列表</text>
		</view>

		<!-- 消息列表 -->
		<scroll-view class="message-list" scroll-y>
			<!-- 医生消息项 -->
			<view class="message-item" v-for="(item, index) in messages" :key="index" @click="goToChat(item.id)">
				<view class="avatar-container">
					<image class="avatar" :src="item.avatar" mode="aspectFill"></image>
					<text class="badge" v-if="item.unreadCount > 0">{{item.unreadCount}}</text>
				</view>

				<view class="message-content">
					<navigator url="/pages/Zixun/chat-detail">
						<view class="message-header">
							<text class="name">{{item.name}}</text>
							<text class="title">{{item.title}}</text>
							<text class="time">{{item.time}}</text>
						</view>
					</navigator>
					<text class="preview">{{item.preview}}</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				messages: [{
						id: 1,
						name: "医生姓名",
						title: "主任医师",
						time: "10:20",
						preview: "消息消息消息预览...",
						unreadCount: 1,
						avatar: "/static/avatars/doctor1.png"
					},
					{
						id: 2,
						name: "医生姓名",
						title: "主治医师",
						time: "10:20",
						preview: "消息消息消息预览...",
						unreadCount: 3,
						avatar: "/static/avatars/doctor2.png"
					},
					{
						id: 3,
						name: "医生姓名",
						title: "专家",
						time: "10:20",
						preview: "消息消息消息预览...",
						unreadCount: 4,
						avatar: "/static/avatars/doctor3.png"
					},
					{
						id: 4,
						name: "患者姓名",
						title: "患者",
						time: "10:20",
						preview: "消息消息消息预览...",
						unreadCount: 0,
						avatar: "/static/avatars/patient.png"
					}
				]
			}
		},
		methods: {
			goToChat(id) {
				uni.navigateTo({
					url: `/pages/chat/chat?id=${id}`
				});
			}
		}
	}
</script>

<style>
	.message-page {
		display: flex;
		height: 2000rpx;
		flex-direction: column;
		background-color: #e1e1e1;
	}

	/* 标题栏样式 */
	.page-header {
		padding: 30rpx;
		width: 100%;
	}

	.header-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		display: flex;
		justify-content: center;
	}

	/* 消息列表容器 */
	.message-list {
		flex: 1;
		padding: 0 20rpx;
		box-sizing: border-box;
	}

	/* 单个消息项样式 */
	.message-item {
		display: flex;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
		background-color: #fff;
		margin-top: 20rpx;
		border-radius: 12rpx;
		padding: 20rpx;
	}

	/* 头像容器 */
	.avatar-container {
		position: relative;
		margin-right: 20rpx;
	}

	.avatar {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		background-color: #eee;
	}

	/* 未读消息标记 */
	.badge {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
		background-color: #f56c6c;
		color: #fff;
		border-radius: 50%;
		width: 40rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		font-size: 24rpx;
	}

	/* 消息内容区域 */
	.message-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.message-header {
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.name {
		font-size: 32rpx;
		color: #333;
		margin-right: 15rpx;
		font-weight: bold;
	}

	.title {
		font-size: 24rpx;
		color: #fff;
		margin-right: auto;
		padding: 0 10rpx;
		background-color: #338cff;
		border-radius: 6rpx;
	}

	.time {
		font-size: 24rpx;
		color: #999;
	}

	.preview {
		font-size: 28rpx;
		color: #666;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>